import bb.cascades 1.3
import bb.WebImageView 1.4
import "../lib"


Container {
    property variant items
    property variant root
    
    onItemsChanged: {
        var results = [];
        for(var i=items.length-1;i>=0;i--){
            var item = items[i];
            item["itemIndex"] = (i+1) + "/"+items.length;
            item["screenWidth"] = com.screenWidth
            item["root"] = root
            results.push(item)
        }
        theDataModel.insertList(results)
    }
    
    ListView {
        id: view
        
        dataModel: GroupDataModel {
            id: theDataModel
            grouping: ItemGrouping.None
        }
        
        layout: StackListLayout {
            orientation: LayoutOrientation.LeftToRight
            headerMode: ListHeaderMode.None
        }
        
        snapMode: SnapMode.LeadingEdge
        flickMode: FlickMode.SingleItem
        scrollIndicatorMode: ScrollIndicatorMode.ProportionalBar
        stickToEdgePolicy: ListViewStickToEdgePolicy.BeginningThenEnd
        layoutProperties: StackLayoutProperties {
        }
        
        onTriggered: {
            var currentItem = dataModel.data(indexPath);
            console.log(currentItem.links[0].url)
            var navRoot = currentItem.root
            var docCom = Qt.createComponent("asset:///ViewSlider.qml")
            var docView = docCom.createObject(navRoot);
            docView.url = currentItem.links[0].url;
            docView.open();
//            navRoot.push(docView);
        }
        
        scrollRole: ScrollRole.None
        
        listItemComponents: [
            ListItemComponent {
                type: "item"
                    TopicSliderItem {
                        thumbnail: ListItemData.thumbnail
                        width: ListItemData.screenWidth
                        height: 360*(preferredWidth/640)
                        title: ListItemData.title
                        itemIndex: ListItemData.itemIndex
                    }
            }
        ]
    }
    
    
    attachedObjects: [
        Common {
            id: com
        }
    ]
}
